#!/bin/sh

# Author: Robert Baarda

export CLASSPATH=`pwd`/interpreter/lib/IntermediateLanguage-1.0.jar:`pwd`/interpreter/lib/aterm-java.jar:`pwd`/interpreter/lib/jjtraveler.jar:`pwd`/interpreter/lib/shared-objects.jar:`pwd`/interpreter/lib/junit-4.4.jar:$CLASSPATH

# Check if we got an argument on the command line.
if [ -n "$1" ]; then	
	echo "INTERPRETER: Creating ast file."
	sglr -p interpreter/stack.tbl -i $1 | implodePT -t > "${1:0:${#1}-4}.ast"
	echo "INTERPRETER: Done..."
		
	echo "INTERPRETER: Executing ast file."
	cd interpreter/bin
	java nl.uva.science.luna.intermediate.interpreter.EntryPoint ../../"${1:0:${#1}-4}.ast" $@
	cd ../..
	echo "INTERPRETER: Execution of ast file ended."
		
	# Clean up.
	rm -f "${1:0:${#1}-4}.ast"
else
	echo "INTERPRETER: No .trm file specified."
	echo "INTERPRETER: Usage: ./interpreter.sh example.trm"
fi
